package com.henu.col05023.common.action;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.henu.col05023.common.CommonUtil;

public class CommonAction extends BaseDispatchAction {

	// testJquery
	public ActionForward deleteFile(ActionMapping mapping, ActionForm form, HttpServletRequest request,
	        HttpServletResponse response) {
		System.out.println(request.getSession().getServletContext().getRealPath(""));
		String realPath=request.getSession().getServletContext().getRealPath("");
		int i  = realPath.lastIndexOf(System.getProperty("file.separator"));
		if(i>=0)
			realPath=realPath.substring(0, realPath.lastIndexOf(System.getProperty("file.separator")));
		String filePath = "";
		try {
			/*
			System.out.println("1"+request.getParameter("filePath"));
			System.out.println("2"+new String(request.getParameter("filePath").getBytes("iso-8859-1"), "gb2312"));
			
			filePath = CommonUtil.nvlToString(request.getParameter("filePath"));
			System.out.println("3"+filePath);
			filePath=CommonUtil.unescape(filePath.replaceAll("%25", "%"));
			System.out.println(filePath);
			*/
			filePath = CommonUtil.nvlToString(new String(
				request.getParameter("filePath").getBytes("iso-8859-1"), "gb2312"));
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		try {
			if(!filePath.equals("")){
				System.out.println(realPath+filePath);
				File file = new File(realPath+filePath);
				if(file.exists())
					file.delete();
			}
		} catch (Exception e) {

		} finally {
			response.setContentType("text/html;charset=utf-8");
			try {
				response.getWriter().write("");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		return null;
	}
}
